<template>
    <el-form
    ref="ruleFormRef"
    :model="ruleForm"
    :rules="rules"
    label-width="120px"
    class="demo-ruleForm"
    :size="formSize"
    status-icon
  >
    <el-form-item label="Activity name" prop="name">
      <el-input v-model="ruleForm.name" />
    </el-form-item>
    <el-form-item label="Activity name" prop="name">
      <el-input v-model="ruleForm.name" />
    </el-form-item>
    <el-form-item label="Activity name" prop="name">
      <el-input v-model="ruleForm.name" />
    </el-form-item>
    <el-form-item label="Activity name" prop="name">
      <el-input v-model="ruleForm.name" />
    </el-form-item>
    <el-form-item label="Activity zone" prop="region">
      <el-select v-model="ruleForm.region" placeholder="Activity zone">
        <el-option label="Zone one" value="shanghai" />
        <el-option label="Zone two" value="beijing" />
      </el-select>
    </el-form-item>
  </el-form>
</template>

<script lang="ts" setup>
import { reactive, ref ,defineProps,computed,defineEmits} from 'vue'
import type { FormInstance, FormRules } from 'element-plus'

const formSize = ref('default')
const ruleFormRef = ref<FormInstance>()
interface RuleForm {
  name?: string
  region?: string,
  name2?:string,
  region2?:string
}
let props = defineProps({
  form: {
    type: Object,
    require: true,
    default:()=>{}
  }
})
let emit =defineEmits(['update:form'])
let ruleForm = computed( {
  get: () => {
    console.log(props.form)
      return props.form
  },
    set: () => {
      emit('update:form')
    }
})
// const ruleForm = reactive<RuleForm>({
//   name: 'Hello',
//   region: '',
// })
const rules = reactive({
  name: [
    { required: true, message: 'Please input Activity name', trigger: 'blur' },
    { min: 3, max: 5, message: 'Length should be 3 to 5', trigger: 'blur' },
  ],
  region: [
    {
      required: true,
      message: 'Please select Activity zone',
      trigger: 'change',
    },
  ],
})
const submitForm = async () => {
  if (!ruleFormRef.value) return
  let result =false
  await ruleFormRef.value.validate((valid, fields) => {
    result=valid
  })
  return result
}
const resetForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return
  formEl.resetFields()
}

defineExpose({
  submitForm,
})

</script>
<style lang="scss" scoped>
</style>